from aiogram import types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup

import client_kb
import sqlite_db
from create_bot import dp


class FSM_EST(StatesGroup):
    doc_type_select = State()


async def create_estonia(message: types.Message, state: FSMContext):
    """Клавиатура с выбором желаемого документа."""

    user_id = message.from_user.id
    await sqlite_db.sql_check_user(user_id)
    await message.answer(
        "Выберите документ для создания", reply_markup=client_kb.kb_est
    )
    await FSM_EST.doc_type_select.set()


@dp.message_handler(state=FSM_EST.doc_type_select)
async def doc_type(message: types.Message, state: FSMContext):
    """Реагирование на выбранный документ и отправка примера заполнения с вызовом соответствующей функции."""
    if message.text == "ID 🇪🇪":
        from handlers.users.generate.est_country.est_id import (
            id_client_first_name_input,
        )

        type_doc = "ID 🇪🇪"
        await sqlite_db.sql_add_country_user(message.from_user.id, "est_id")
        await state.update_data(type=type_doc)
        await id_client_first_name_input(message, state)
    if message.text == "BILL 🇪🇪":
        from handlers.users.generate.est_country.est_bill import bill_first_name_input

        type_doc = "BILL 🇪🇪"
        await sqlite_db.sql_add_country_user(message.from_user.id, "est_bill")
        await state.update_data(type=type_doc)
        await bill_first_name_input(message, state)
    if message.text == "Назад ◀️":
        from handlers.users.menu import command_create_menu_notcallback

        await command_create_menu_notcallback(message)
